﻿Public Class main

    Private WithEvents t As New System.Windows.Forms.Timer With {.Enabled = False, .Interval = 120}

    Private Sub t_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles t.Tick
        Try


            Dim s As String = TextBox1.Text
            Dim c = s.Substring(0, 1)
            TextBox1.Text = s.Substring(s.Length - (s.Length - 1)) & c

            Dim s2 As String = TextBox2.Text
            Dim c2 = s2.Substring(0, 1)
            TextBox2.Text = s2.Substring(s2.Length - (s2.Length - 1)) & c2

            Dim s3 As String = TextBox3.Text
            Dim c3 = s3.Substring(0, 1)
            TextBox3.Text = s3.Substring(s3.Length - (s3.Length - 1)) & c3

            Dim s4 As String = TextBox4.Text
            Dim c4 = s4.Substring(0, 1)
            TextBox4.Text = s4.Substring(s4.Length - (s4.Length - 1)) & c4

        Catch ex As Exception

        End Try
    End Sub
    Dim lsttext = " ______  ______   ______  __    _     ______   ______   ______   ______  _    _   ______    _     _  _____  ______  _______  _    _   ______   _          _    _   ______   ______  _______    ______   ______  ______   ______  ______   ______  _______  ______   ______                 "

    Dim lsttext2 = "| |     | |  | | / |      \ \  | |   | |  | | | |  | \ | |  | | | |     | |  | | | |       | |   | |  | |  | |  | \   | |   | |  | | | |  | | | |        | |  | | / |  | \ / |        | |     | | ____ | |     | |  \ \ | |     | |  | \ | |  | |   | |   / |  | \ | |  | \                "

    Dim lsttext3 = "| |---- | |__| | '------.  \_\_| |   | |__| | | |__|_/ | |__| | | |     | |--| | | |----   \ \   / /  | |  | |__| |   | |   | |  | | | |__| | | |   _    | |--| | | |  | | '------.   | |     | |  | | | |---- | |  | | | |---- | |__| | | |__| |   | |   | |  | | | |__| |                "


    Dim lsttext4 = "|_|____ |_|  |_|  ____|_/  ____|_|   |_|  |_| |_|      |_|  |_| |_|____ |_|  |_| |_|____    \_\_/_/  _|_|_ |_|  \_\   |_|   \_|__|_| |_|  |_| |_|__|_|   |_|  |_| \_|__|_/  ____|_/   |_|     |_|__|_| |_|____ |_|  |_| |_|____ |_|  \_\ |_|  |_|   |_|   \_|__|_/ |_|  \_\                "
    Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        While TextRenderer.MeasureText(lsttext, TextBox1.Font).Width < TextBox1.Width
            lsttext &= " "
        End While


        lsttext = lsttext.Substring(0, lsttext.Length - 1)
        TextBox1.Text = lsttext
        TextBox1.ReadOnly = True

        '2. Textbox

        While TextRenderer.MeasureText(lsttext2, TextBox2.Font).Width < TextBox2.Width
            lsttext2 &= " "
        End While


        lsttext2 = lsttext2.Substring(0, lsttext2.Length - 1)
        TextBox2.Text = lsttext2
        TextBox2.ReadOnly = True

        '3. Textbox
        While TextRenderer.MeasureText(lsttext3, TextBox3.Font).Width < TextBox3.Width
            lsttext3 &= " "
        End While


        lsttext3 = lsttext3.Substring(0, lsttext3.Length - 1)
        TextBox3.Text = lsttext3
        TextBox3.ReadOnly = True

        '4. Textbox
        While TextRenderer.MeasureText(lsttext4, TextBox4.Font).Width < TextBox4.Width
            lsttext4 &= " "
        End While


        lsttext4 = lsttext4.Substring(0, lsttext4.Length - 1)
        TextBox4.Text = lsttext4
        TextBox4.ReadOnly = True

        t.Interval = 120
        t.Enabled = True
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ErrorProvider1.Clear()
        
        If TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox8.Text = "" Then

            If TextBox5.Text = "" Then
                ErrorProvider1.SetError(TextBox5, "You must enter a value in the '[Host Name & Port]' field")
            End If

            If TextBox6.Text = "" Then
                ErrorProvider1.SetError(TextBox6, "You must enter a value in the '[Domain or Subdomain]' field")
            End If

            If TextBox7.Text = "" Then
                ErrorProvider1.SetError(TextBox7, "You must enter a value in the '[Admin Email]' field")
            End If

            If TextBox8.Text = "" Then
                ErrorProvider1.SetError(TextBox8, "You must enter a value in the '[Path on Server]' field")
            End If
        Else

            If TextBox9.Text = "Click Me!" Then
                ListBox1.Items.Add(TextBox5.Text & "," & TextBox6.Text & "," & TextBox7.Text & "," & TextBox8.Text & ",no")

            Else
                ListBox1.Items.Add(TextBox5.Text & "," & TextBox6.Text & "," & TextBox7.Text & "," & TextBox8.Text & "," & TextBox9.Text)

            End If
            
        End If




    End Sub



    Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
        If TextBox5.Text.Contains(":") = True Then
            TextBox5.BackColor = Color.GreenYellow
        Else
            TextBox5.BackColor = Color.Red
        End If



    End Sub

    Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
        If TextBox6.Text.Contains(".") = True Then
            

                TextBox6.BackColor = Color.GreenYellow
                Subdomain_Editor.TextBox1.Text = "subdomain." & TextBox6.Text

        Else
            TextBox6.BackColor = Color.Red
        End If
    End Sub

    Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged
        If TextBox7.Text.Contains("@") = True Then
            If TextBox7.Text.Contains(".") = True Then
                TextBox7.BackColor = Color.GreenYellow
            Else
                TextBox7.BackColor = Color.Red
            End If
        Else
            TextBox7.BackColor = Color.Red
        End If
    End Sub

    Private Sub TextBox8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged
        If TextBox8.Text.Contains("/") = True Then
            TextBox8.BackColor = Color.GreenYellow
        Else
            TextBox8.BackColor = Color.Red
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ListBox1.Items.Remove(ListBox1.SelectedItem)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RichTextBox1.Text = ""
        For Each item As String In ListBox1.Items
            Dim lineArr() As String = item.Split(",")
            If lineArr(0) = "" Then

            Else

                RichTextBox1.Text = RichTextBox1.Text + "<VirtualHost " & lineArr(0) & ">" + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + "      ServerAdmin " & lineArr(2) + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + "      ServerName " & lineArr(1) + vbNewLine
                If lineArr(4) = "no" Then
                Else
                    RichTextBox1.Text = RichTextBox1.Text + "      ServerAlias " & lineArr(4) + vbNewLine
                End If

                RichTextBox1.Text = RichTextBox1.Text + "      DocumentRoot " & lineArr(3) + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + "	          <Directory " & lineArr(3) & ">" + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + "                   Options Indexes FollowSymLinks MultiViews" + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + "                   AllowOverride All" + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + "                   Order allow,deny" + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + "                   allow from all" + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + "             </Directory>" + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + "</VirtualHost>" + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + vbNewLine
                RichTextBox1.Text = RichTextBox1.Text + vbNewLine








            End If

        Next
    End Sub

    
    Private Sub main_ResizeEnd(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.ResizeEnd
        While TextRenderer.MeasureText(lsttext, TextBox1.Font).Width < TextBox1.Width
            lsttext &= " "
        End While


        lsttext = lsttext.Substring(0, lsttext.Length - 1)
        TextBox1.Text = lsttext
        TextBox1.ReadOnly = True

        '2. Textbox

        While TextRenderer.MeasureText(lsttext2, TextBox2.Font).Width < TextBox2.Width
            lsttext2 &= " "
        End While


        lsttext2 = lsttext2.Substring(0, lsttext2.Length - 1)
        TextBox2.Text = lsttext2
        TextBox2.ReadOnly = True

        '3. Textbox
        While TextRenderer.MeasureText(lsttext3, TextBox3.Font).Width < TextBox3.Width
            lsttext3 &= " "
        End While


        lsttext3 = lsttext3.Substring(0, lsttext3.Length - 1)
        TextBox3.Text = lsttext3
        TextBox3.ReadOnly = True

        '4. Textbox
        While TextRenderer.MeasureText(lsttext4, TextBox4.Font).Width < TextBox4.Width
            lsttext4 &= " "
        End While


        lsttext4 = lsttext4.Substring(0, lsttext4.Length - 1)
        TextBox4.Text = lsttext4
        TextBox4.ReadOnly = True

        t.Interval = 120
        t.Enabled = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim SaveFile As New SaveFileDialog
        SaveFile.FileName = "default"
        SaveFile.Filter = "Host File (without suffix)"
        SaveFile.ShowDialog()
        Try
            Dim Write As New System.IO.StreamWriter(SaveFile.FileName)
            Write.Write(RichTextBox1.Text)
            Write.Close()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim text As String
        text = RichTextBox1.Text
        Clipboard.SetDataObject(text, True)
    End Sub

    Private Sub TextBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox9.Click
        Me.Hide()
        Subdomain_Editor.Show()
    End Sub
End Class
